<?php
session_start();

require_once "includes/config.php";
require_once "includes/functions.php";

require_once 'includes/class.phpmailer.php';
$productOwner=mysql_fetch_array(mysql_query("select * from tbl_product where product_id='".$_POST['product_id']."'"));
$owner_id=$productOwner['posted_by'];
//echo $recieverid	=	$_REQUEST['ownerid'];
//echo $jobid		=	$_REQUEST['jobid2'];
//echo $type		=	$_REQUEST['type2'];
//echo $txtSub		=	$_REQUEST['txtSub2'];
//echo $txtQuery	=	$_REQUEST['txtQuery2'];
//echo $productname	=	$_REQUEST['productname2'];

//if($_POST['type2']=="job")
//{
  mysql_query("insert into tbl_messages(senderid,recieverid,productid,subject,message,posteddate,status,section) values('".$_SESSION['user_id_sess']."','".$owner_id."','".stripslashes($productOwner['product_name'])."','".$_POST['txtSub2']."','".date("Y-m-d")."','1','Job')");
  $emailContent="Subject: ".stripslashes($productOwner['product_name'])."<br>";
  $emailContent.="Message: ".stripslashes($_POST['txtQuery2'])."<br>";
//}
//else
//{
//  $emailContent="You are receiving this message because (".$_SESSION['user_name'].") has sent you message towards (<a href=index.php?products=".$_POST['productid'].">".$_POST['productname2']."</a>)<p>Message:".$_POST['txtQuery2']."</p>";
 // mysql_query("insert into tbl_messages(senderid,recieverid,productid,subject,message,posteddate,status) values('".$_SESSION['user_id_sess']."','".$owner_id."','".$_POST['jobid2']."','".$_POST['txtSub2']."','".$emailContent."','".date("Y-m-d")."','1')");
//}


$mailmsg="<table width='100%' border='0' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px; line-height:25px'>

<tr>
  <td height='32' colspan='2' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;'>".$emailContent."</td>
</tr>


</table>
";

$qry = mysql_query("select email from tbl_users where user_id='".$owner_id."'") or die(mysql_error());
$cnt = mysql_num_rows($qry);
if($cnt>0)
{
  $user = mysql_fetch_array($qry);
  $email = $user['email'];
  $mail = new PHPMailer(); // defaults to using php "mail()"
  $mail->MsgHTML($mailmsg);
  $mail->From       = "mail@swapen.com";
  $mail->FromName   = "Swapen.com";
  $mail->Subject    = "Suggestion Mail";
  $mail->AddAddress($email);
  $mail->Send();
  
  echo 'ok';
  //$_SESSION['msg']="Messege sent successfully";
}
else
{
  echo 'fail';
}

?>

